package rule.rulechain;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import static junit.framework.TestCase.assertTrue;

/**
 * Created by fengxiangxiang on 2016-10-14.
 */
public class UseRuleChain {
    @Rule
    public TestRule chain = RuleChain
            .outerRule(new LoggingRule("step1:outer rule"))
            .around(new LoggingRule("step2:middle rule"))
            .around(new LoggingRule("step3:inner rule"));

    @Test
    public void example() {
        System.out.println("\n test started");
        assertTrue(true);
    }

    private class LoggingRule implements TestRule {
        private String s;
        public LoggingRule(String s) {
            this.s = s;

        }

        public Statement apply(Statement statement, Description description) {
            System.out.println(this.s+" started");
            return statement;
        }
    }
}